package io.github.talelin.latticy.controller.zty;

import io.github.talelin.core.annotation.LoginRequired;
import io.github.talelin.latticy.pojo.OutputList;
import io.github.talelin.latticy.pojo.ReplenishList;
import io.github.talelin.latticy.service.DispatchListService;
import io.github.talelin.latticy.service.OutputListService;
import io.github.talelin.latticy.vo.UpdatedVO;
import io.github.talelin.latticy.vo.zty.OutputDetailVO;
import io.github.talelin.latticy.vo.zty.OutputListVO;
import io.github.talelin.latticy.vo.zty.ReplenishDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;

@RestController
@RequestMapping("/output")
public class OutputController {

    @Autowired
    OutputListService outputListService;

    @Autowired
    DispatchListService dispatchListService;

    @GetMapping("/outputList")
    @LoginRequired
    public List<OutputListVO> getOutputList(){
        List<OutputListVO> outputLists = outputListService.getOutputLists();
        return outputLists;
    }


    @GetMapping("/details/{id}")
    @LoginRequired
    public List<OutputDetailVO>  getReplenishApplyDetailById(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id){
        System.out.println(id);
        List<OutputDetailVO> outputDetailVOs = outputListService.getOutputDetailsByListId(id);
        return outputDetailVOs;
    }


    @PutMapping("/pass/{id}/{handlerId}")
    @LoginRequired
    @Transactional
    public UpdatedVO passReplenishApply(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id, @PathVariable(value = "handlerId") @Positive(message = "{handlerId.positive}") Integer handlerId){
        System.out.println(handlerId);
        System.out.println(id);
        OutputList outputList = outputListService.getBaseMapper().selectById(id);
        outputList.setStatus(3);
        int i = outputListService.getBaseMapper().updateById(outputList);
        dispatchListService.createDispatchListByOutputList(id,handlerId);
        return new UpdatedVO(16);
    }
}
